/**
 * Created by IntelliJ
 * Author:熊磊
 */
//顺序存储二叉树
public class ArrBinaryTree {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7};
        ArrBinaryTree tree = new ArrBinaryTree(arr);
        tree.preOrder();
    }


    private int[] arr;

    public ArrBinaryTree(int[] arr) {
        this.arr = arr;
    }

    //前序遍历
    public void preOrder(int index){
        System.out.println(arr[index]);
        if ((index*2+1)<arr.length){
            preOrder(index*2+1);
        }
        if ((index*2+2)<arr.length){
            preOrder(index*2+2);
        }
    }
    public void preOrder(){
        if (arr==null&&arr.length==0){
            System.out.println("数组为空");
            return;
        }
        preOrder(0);
    }

}
